{
	template:`
    <m-page @back="back" :title="title">
        <m-top></m-top>
        <m-title>{{title}}
			<template #action>
				<m-button v-if="edit" @click="openDetail({status:'Y',store:{user:{}}})">新增</m-button>
			</template>
        </m-title>
		<m-top></m-top>
		<m-list ref="list" :url="url" :params="params" :bottom="0" :search="search">
			<template #item="{item}">
				<m-card join @click="openDetail(item)">
					<div class="flex padding-sm align-center">
                        <div class="cu-tag radius" :class="'bg-'+item.store.color">{{item.store.name}}</div>
						<div class="flex-sub padding-lr-sm">
						    <span>{{item.realName}}</span>
						    <span class="text-sm text-gray padding-left-xs">{{item.phoneNum}}</span>
						</div>
					    <div v-if="item.status=='Y'" class="text-right">
						    <div v-if="item.powers.indexOf('A')>=0" class="cu-tag radius line-blue sm">管理</div>
						    <div v-if="item.powers.indexOf('B')>=0" class="cu-tag radius line-green sm">店长</div>
					    </div>
					    <status v-else :value="item.status"/>
					</div>
					<div v-if="edit&&(item.wages||item.orderRatio||item.rechargeRatio)" class="text-sm padding-lr-sm padding-bottom-sm">
					    <span v-if="item.wages">月工资{{formatAmount(item.wages)}}元</span>
					    <span v-if="item.orderRatio" class="padding-left-sm">订单提成{{formatAmount(item.orderRatio)}}%</span>
					    <span v-if="item.rechargeRatio" class="padding-left-sm">充值提成{{formatAmount(item.rechargeRatio)}}%</span>
					</div>
				</m-card>
			</template>
		</m-list>
		<m-modal ref="detail" title="员工信息" @close="$refs.list.refresh()">
			<div v-if="showDetail">
				<m-card>
                    <div class="cu-form-group">
                        <div class="title text-red">姓名</div>
                        <m-input :operable="edit" v-model="showDetail.realName" placeholder="请输入姓名"></m-input>
                        <m-switch v-if="edit" v-model="showDetail.status"></m-switch>
                    </div>
                    <div class="cu-form-group">
                        <div class="title text-red">手机号</div>
                        <m-input :operable="edit" v-model="showDetail.phoneNum" placeholder="请输入手机号"></m-input>
                    </div>
                    <div class="cu-form-group">
                        <div class="title" :class="showDetail.oid?'':'text-red'">密码</div>
                        <m-input :operable="edit" v-model="showDetail.password" :placeholder="showDetail.oid?'空着就不修改密码':'请输入密码'"></m-input>
                    </div>
                    <div class="cu-form-group">
                        <div class="title text-red">店铺</div>
                        <m-form-item>
                            <div v-if="showDetail.store.oid" class="flex-sub">{{showDetail.store.name}} <span class="text-sm">{{showDetail.store.user.realName}}</span></div>
                            <div v-else-if="edit" class="flex-sub text-placeholder">请选择店铺</div>
                            <template #action>
                                <m-button v-if="edit"  @click="selectStore(showDetail)" size="sm">选择</m-button>
                            </template>
                        </m-form-item>
                    </div>
                    <div class="cu-form-group">
                        <div class="title">权限</div>
                        <m-dict-option :operable="edit" class="flex-sub" v-model="showDetail.powers" multiple type="member.base.model.UserInfo!powers"></m-dict-option>
                    </div>
                    <div v-if="edit" class="cu-form-group">
                        <div class="title">月工资</div>
                        <m-input-number :operable="edit" v-model="showDetail.wages" placeholder="请输入月工资"></m-input-number>
                    </div>
                    <div v-if="edit" class="cu-form-group">
                        <div class="title">订单提成</div>
                        <m-input-number :operable="edit" v-model="showDetail.orderRatio" placeholder="请输入订单提成"></m-input-number>
                        <div>%</div>
                    </div>
                    <div v-if="edit" class="cu-form-group">
                        <div class="title">充值提成</div>
                        <m-input-number :operable="edit" v-model="showDetail.rechargeRatio" placeholder="请输入充值提成"></m-input-number>
                        <div>%</div>
                    </div>
				</m-card>
                <div class="flex padding-lr-sm padding-bottom">
                    <div class="flex-sub flex flex-direction padding-lr-xs">
                        <m-button @click="closeDetail()" line>关闭</m-button>
                    </div>
                    <div v-if="edit" class="flex-sub flex flex-direction padding-lr-xs">
                        <m-button @click="save">保存</m-button>
                    </div>
                </div>
			</div>
		</m-modal>
    </m-page>
	`,
	props: ['param','parentVue'],
	data:function(){
		return {
		    edit:false,
            title:'员工管理',
            url:'action/base/userInfo/getList',
            params:{},
            search:[
                {title:'姓名',name:'realName@like',input:'text'},
                {title:'手机号',name:'phoneNum@like',input:'text'},
                {title:'店铺',name:'store.name@like',input:'text'}
            ],
            showDetail:null
		};
	},
	mounted(){
	    this.edit=this.param.edit=='true';
	    this.title='员工'+(this.edit?'管理':'查询');
	},
	methods:{
        openDetail:function(item){
            this.showDetail=Object.assign({},item);
            this.$refs.detail.open();
        },
        closeDetail:function(){
            this.$refs.detail.close();
        },
        selectStore:function(model){
            let selectOid=model.store?model.store.oid:'';
	        this.openPage('common/selectStore.js',{title:'选择店铺',selectOid:selectOid},(flag,obj)=>{
	            if(flag){
	                model.store=obj;
                }
	        });
        },
        save:function(){
            this.requestData('action/base/userInfo/save',
                {model:this.showDetail},
                (data)=>{
                    if(data.code==0){
                        this.remind().success(data.msg);
                        this.closeDetail();
                    }else{
                        this.remind().error(data.msg);
                    }
                }
            );
        }
	}
}